local UIBase = require("view.UIBase")
local FightTransition = class("FightTransition", UIBase)
local Color = require("utils.Color")

function FightTransition:ctor()
    local resource = {
        path = "Prefabs/Popup",
        name = "FightTransition",
        canvas = 3
    }
    FightTransition.super.ctor(self, resource)
end

function FightTransition:setTip(text)
    self._textTip.text = text
end

function FightTransition:play(callback)
    self._callback = callback
    self._imageDis = self._imageBg.gameObject:GetComponent(typeof(CS.Coffee.UIEffects.UIDissolve))
    self._textDis = self._textTip.gameObject:GetComponent(typeof(CS.Coffee.UIEffects.UIDissolve))
    self._imageDis.effectFactor = 0
    self._imageDis.effectFactor = 0
    self._start = true
end

function FightTransition:update(dt)
    if not self._start then
        return
    end
    self._imageDis.effectFactor = self._imageDis.effectFactor + dt * 0.5
    self._textDis.effectFactor = self._textDis.effectFactor + dt * 0.5
    if self._imageDis.effectFactor >= 1 and self._textDis.effectFactor >= 1 then
        if self._callback then
            self._callback()
        end
        self:close()
        self._start = false
    end
end

return FightTransition
